package top.heliming.youyou.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import top.heliming.youyou.service.GoodsHtmlService;
import top.heliming.youyou.service.GoodsService;

/**
 * description: //TODO
 *
 * @author: heliming
 * @date:2019/06/04 下午 10:48
 */
@Controller
@RequestMapping("item")
public class GoodsController {

  @Autowired
  private GoodsService goodsService;

  @Autowired
  private GoodsHtmlService goodsHtmlService;
  /**
   * 跳转到商品详情页
   * @param model
   * @param id
   * @return
   */
  @GetMapping("{id}.html")
  public String toItemPage(Model model, @PathVariable("id")Long id){
    // 加载所需的数据
    Map<String, Object> modelMap = this.goodsService.loadModel(id);
    // 放入模型
    model.addAllAttributes(modelMap);
    // 页面静态化
    this.goodsHtmlService.createHtml(id);
    return "item";
  }
}